#include "maintain.h"
#include "ui_maintain.h"
#include <qmessagebox.h>

#include <QButtonGroup>

maintain::maintain(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::maintain)
{
    ui->setupUi(this);
    this->setFixedSize(1140, 786);
    this->setWindowTitle("维护校正");
    this->setWindowFlags(this->windowFlags() &~ Qt::WindowMinMaxButtonsHint);
    ui->weiHuZhiling->setReadOnly(true);

    cusMsg = new CustomMessageBox();
    cfg = new ConfigFileService();

    /* 获取配置文件耗材类型 */
    consumableFromConfig = cfg->getConsumablesType();

    /* 写入耗材类型 */
    for(int i = 0; i < consumableFromConfig.size(); i++){
        ui->haocai->addItem(consumableFromConfig[i]);
    }

    ui->jiaresi->setRange(0, 1000);

    QButtonGroup * BtnGroupA = new QButtonGroup();
    BtnGroupA->addButton(ui->fengshanOn, 0);
    BtnGroupA->addButton(ui->fengshanOff, 1);
    BtnGroupA->setExclusive(true);
    ui->fengshanOn->setChecked(true);

    QButtonGroup * BtnGroupB = new QButtonGroup();
    BtnGroupB->addButton(ui->paifengOn, 0);
    BtnGroupB->addButton(ui->paifengOff, 1);
    BtnGroupB->setExclusive(true);

    ui->duiliu->setRange(0, 1000);

    ui->chuanganqi->setRange(-5.0, 5.0);

    ui->weizhiStep->setValue(8715);

    QButtonGroup * BtnGroupD = new QButtonGroup();
    BtnGroupD->addButton(ui->kaiguanOn, 0);
    BtnGroupD->addButton(ui->kaiguanOff, 1);
    BtnGroupD->setExclusive(true);
    ui->kaiguanOn->setChecked(true);

    ui->qiangduZhi->setRange(0, 32000);

    ui->zengyiZhi->setRange(0, 32000);

    ui->jiaozheng->setRange(0, 1000);

    QButtonGroup * BtnGroupE = new QButtonGroup();
    BtnGroupE->addButton(ui->lockPing, 0);
    BtnGroupE->addButton(ui->lockUnPing, 1);
    BtnGroupE->setExclusive(true);
    ui->lockPing->setChecked(true);

    QButtonGroup * BtnGroupF = new QButtonGroup();
    BtnGroupF->addButton(ui->lockOn, 0);
    BtnGroupF->addButton(ui->lockOff, 1);
    BtnGroupF->setExclusive(true);
    ui->lockOn->setChecked(true);

    QButtonGroup * BtnGroupG = new QButtonGroup();
    BtnGroupG->addButton(ui->searchPing, 0);
    BtnGroupG->addButton(ui->searchUnPing, 1);
    BtnGroupG->setExclusive(true);
    ui->searchPing->setChecked(true);

    QButtonGroup * BtnGroupH = new QButtonGroup();
    BtnGroupH->addButton(ui->searchOn, 0);
    BtnGroupH->addButton(ui->searchOff, 1);
    BtnGroupH->setExclusive(true);
    ui->searchOn->setChecked(true);


    /* 获取当前选中设备 */
    ConnectedDeviceStruct tCDev = ui->devices_2->currentData().value<ConnectedDeviceStruct>();
    this->instruct = tCDev.instructionsService;
    this->ip = tCDev.dev.ip;
    this->port = tCDev.dev.port;

    //    QTimer *timer = new QTimer(this);
    //    connect(timer, SIGNAL(timeout()), this, SLOT(timerUpdate()));
    //    timer->start(500);

    connect(ui->heat_8, &QPushButton::clicked, this, [=](){
        ui->stackedWidget->setCurrentIndex(0);

        ui->heat_8->setDown(true);

        ui->heat_1->setDown(false);
        ui->heat_2->setDown(false);
        ui->heat_3->setDown(false);
        ui->heat_4->setDown(false);
        ui->heat_5->setDown(false);
        ui->heat_6->setDown(false);
        ui->heat_7->setDown(false);
        ui->heat_9->setDown(false);

    });

    connect(ui->heat_9, &QPushButton::clicked, this, [=](){
        ui->stackedWidget->setCurrentIndex(1);

        ui->heat_9->setDown(true);

        ui->heat_1->setDown(false);
        ui->heat_2->setDown(false);
        ui->heat_3->setDown(false);
        ui->heat_4->setDown(false);
        ui->heat_5->setDown(false);
        ui->heat_6->setDown(false);
        ui->heat_7->setDown(false);
        ui->heat_8->setDown(false);
    });

    connect(ui->heat_1, &QPushButton::clicked, this, [=](){
        ui->stackedWidget->setCurrentIndex(2);

        ui->heat_1->setDown(true);

        ui->heat_8->setDown(false);
        ui->heat_2->setDown(false);
        ui->heat_3->setDown(false);
        ui->heat_4->setDown(false);
        ui->heat_5->setDown(false);
        ui->heat_6->setDown(false);
        ui->heat_7->setDown(false);
        ui->heat_9->setDown(false);
    });

    connect(ui->heat_2, &QPushButton::clicked, this, [=](){
        ui->stackedWidget->setCurrentIndex(3);

        ui->heat_2->setDown(true);

        ui->heat_1->setDown(false);
        ui->heat_8->setDown(false);
        ui->heat_3->setDown(false);
        ui->heat_4->setDown(false);
        ui->heat_5->setDown(false);
        ui->heat_6->setDown(false);
        ui->heat_7->setDown(false);
        ui->heat_9->setDown(false);
    });

    connect(ui->heat_3, &QPushButton::clicked, this, [=](){
        ui->stackedWidget->setCurrentIndex(4);

        ui->heat_3->setDown(true);

        ui->heat_1->setDown(false);
        ui->heat_2->setDown(false);
        ui->heat_8->setDown(false);
        ui->heat_4->setDown(false);
        ui->heat_5->setDown(false);
        ui->heat_6->setDown(false);
        ui->heat_7->setDown(false);
        ui->heat_9->setDown(false);
    });

    connect(ui->heat_4, &QPushButton::clicked, this, [=](){
        ui->stackedWidget->setCurrentIndex(5);

        ui->heat_4->setDown(true);

        ui->heat_1->setDown(false);
        ui->heat_2->setDown(false);
        ui->heat_3->setDown(false);
        ui->heat_8->setDown(false);
        ui->heat_5->setDown(false);
        ui->heat_6->setDown(false);
        ui->heat_7->setDown(false);
        ui->heat_9->setDown(false);
    });

    connect(ui->heat_5, &QPushButton::clicked, this, [=](){
        ui->stackedWidget->setCurrentIndex(6);

        ui->heat_5->setDown(true);

        ui->heat_1->setDown(false);
        ui->heat_2->setDown(false);
        ui->heat_3->setDown(false);
        ui->heat_4->setDown(false);
        ui->heat_8->setDown(false);
        ui->heat_6->setDown(false);
        ui->heat_7->setDown(false);
        ui->heat_9->setDown(false);
    });

    connect(ui->heat_6, &QPushButton::clicked, this, [=](){
        ui->stackedWidget->setCurrentIndex(7);

        ui->heat_6->setDown(true);

        ui->heat_1->setDown(false);
        ui->heat_2->setDown(false);
        ui->heat_3->setDown(false);
        ui->heat_4->setDown(false);
        ui->heat_5->setDown(false);
        ui->heat_8->setDown(false);
        ui->heat_7->setDown(false);
        ui->heat_9->setDown(false);
    });

    connect(ui->heat_7, &QPushButton::clicked, this, [=](){
        ui->stackedWidget->setCurrentIndex(8);

        ui->heat_7->setDown(true);

        ui->heat_1->setDown(false);
        ui->heat_2->setDown(false);
        ui->heat_3->setDown(false);
        ui->heat_4->setDown(false);
        ui->heat_5->setDown(false);
        ui->heat_6->setDown(false);
        ui->heat_8->setDown(false);
        ui->heat_9->setDown(false);
    });


    connect(ui->detect_1, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_2->setCurrentIndex(0);
        ui->detect_1->setDown(true);

        ui->detect_2->setDown(false);
        ui->detect_3->setDown(false);
        ui->detect_4->setDown(false);
    });


    connect(ui->detect_2, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_2->setCurrentIndex(1);
        ui->detect_2->setDown(true);

        ui->detect_1->setDown(false);
        ui->detect_3->setDown(false);
        ui->detect_4->setDown(false);
    });

    connect(ui->detect_3, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_2->setCurrentIndex(2);
        ui->detect_3->setDown(true);

        ui->detect_2->setDown(false);
        ui->detect_1->setDown(false);
        ui->detect_4->setDown(false);
    });

    connect(ui->detect_4, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_2->setCurrentIndex(3);
        ui->detect_4->setDown(true);

        ui->detect_2->setDown(false);
        ui->detect_3->setDown(false);
        ui->detect_1->setDown(false);
    });

    connect(ui->state_1, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_3->setCurrentIndex(0);

        ui->state_1->setDown(true);

        ui->state_2->setDown(false);
        ui->state_3->setDown(false);
    });

    connect(ui->state_2, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_3->setCurrentIndex(1);

        ui->state_2->setDown(true);

        ui->state_1->setDown(false);
        ui->state_3->setDown(false);
    });

    connect(ui->state_3, &QPushButton::clicked, this, [=](){
        ui->stackedWidget_3->setCurrentIndex(2);

        ui->state_3->setDown(true);

        ui->state_2->setDown(false);
        ui->state_1->setDown(false);
    });



    connect(ui->lockBtn1, &QPushButton::clicked, this, [=](){
        instruct->weiHuData.clear();

        QString pingbi;
        if(ui->lockPing->isChecked() == true){pingbi = "0";}
        else if(ui->lockUnPing->isChecked() == true){pingbi = "1";}

        QString kaiguan;
        if(ui->lockOn->isChecked() == true){kaiguan = "0";}
        else if(ui->lockOff->isChecked() == true){kaiguan = "1";}
        /*发送数据前校验是否连接*/
        if(!instruct->m_socketClient->isConnected()){
            instruct->establishConnection(ip, port.toInt());
        }
        instruct->sendWeihuMensuo(pingbi, kaiguan, QString::number(3));
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
        /* 渲染指令到UI */
        this->renderWeihuZhiling();

        if(instruct->weiHuData.size() == 0){
            /*发送数据前校验是否连接*/
            if(!instruct->m_socketClient->isConnected()){
                instruct->establishConnection(ip, port.toInt());
            }
            instruct->sendWeihuMensuo(pingbi, kaiguan, QString::number(3));
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
            /* 渲染指令到UI */
            this->renderWeihuZhiling();

            if(instruct->weiHuData.size() == 0){
                cusMsg->show(this, CMsg::CWarning, "维护校正", "维护信息为空");
                this->isEmptyData("通信异常：维护信息为空");

            }
            else{
                cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
                //                if(instruct->weiHuData[1] == "0"){
                //                    ui->lockPing->setChecked(true);
                //                }
                //                else if(instruct->weiHuData[1] == "1"){
                //                    ui->lockUnPing->setChecked(true);
                //                }

                //                if(instruct->weiHuData[2] == "0"){
                //                    ui->lockOn->setChecked(true);
                //                }
                //                else if(instruct->weiHuData[2] == "1"){
                //                    ui->lockOff->setChecked(true);
                //                }
            }
        }
        else{
            cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
            //            if(instruct->weiHuData[1] == "0"){
            //                ui->lockPing->setChecked(true);
            //            }
            //            else if(instruct->weiHuData[1] == "1"){
            //                ui->lockUnPing->setChecked(true);
            //            }

            //            if(instruct->weiHuData[2] == "0"){
            //                ui->lockOn->setChecked(true);
            //            }
            //            else if(instruct->weiHuData[2] == "1"){
            //                ui->lockOff->setChecked(true);
            //            }
        }
    });

    connect(ui->jianceBtn1, &QPushButton::clicked, this, [=](){
        instruct->weiHuData.clear();

        QString pingbi;
        if(ui->searchPing->isChecked() == true){pingbi = "0";}
        else if(ui->searchUnPing->isChecked() == true){pingbi = "1";}

        QString kaiguan;
        if(ui->searchOn->isChecked() == true){kaiguan = "0";}
        else if(ui->searchOff->isChecked() == true){kaiguan = "1";}
        /*发送数据前校验是否连接*/
        if(!instruct->m_socketClient->isConnected()){
            instruct->establishConnection(ip, port.toInt());
        }
        instruct->sendWeihuBigai(pingbi, kaiguan, QString::number(3));
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        if(instruct->weiHuData.size() == 0){
            /*发送数据前校验是否连接*/
            if(!instruct->m_socketClient->isConnected()){
                instruct->establishConnection(ip, port.toInt());
            }
            instruct->sendWeihuBigai(pingbi, kaiguan, QString::number(3));
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            if(instruct->weiHuData.size() == 0){
                cusMsg->show(this, CMsg::CWarning, "维护校正", "维护信息为空");
                this->isEmptyData("通信异常：维护信息为空");
            }
            else{
                cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
                //                if(instruct->weiHuData[1] == "0"){
                //                    ui->searchPing->setChecked(true);
                //                }
                //                else if(instruct->weiHuData[1] == "1"){
                //                    ui->searchUnPing->setChecked(true);
                //                }

                //                if(instruct->weiHuData[2] == "0"){
                //                    ui->searchOn->setChecked(true);
                //                }
                //                else if(instruct->weiHuData[2] == "1"){
                //                    ui->searchOff->setChecked(true);
                //                }
            }
        }
        else{
            cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
            //            if(instruct->weiHuData[1] == "0"){
            //                ui->searchPing->setChecked(true);
            //            }
            //            else if(instruct->weiHuData[1] == "1"){
            //                ui->searchUnPing->setChecked(true);
            //            }

            //            if(instruct->weiHuData[2] == "0"){
            //                ui->searchOn->setChecked(true);
            //            }
            //            else if(instruct->weiHuData[2] == "1"){
            //                ui->searchOff->setChecked(true);
            //            }
        }
    });

    connect(ui->lockJiaozhengBtn1, &QPushButton::clicked, this, [=](){
        instruct->weiHuData.clear();

        QString zhankongbi = ui->jiaozheng->text();
        /*发送数据前校验是否连接*/
        if(!instruct->m_socketClient->isConnected()){
            instruct->establishConnection(ip, port.toInt());
        }
        instruct->sendWeihuMensuojiaozheng(zhankongbi, QString::number(1));
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        if(instruct->weiHuData.size() == 0){
            /*发送数据前校验是否连接*/
            if(!instruct->m_socketClient->isConnected()){
                instruct->establishConnection(ip, port.toInt());
            }
            instruct->sendWeihuMensuojiaozheng(zhankongbi, QString::number(1));
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            if(instruct->weiHuData.size() == 0){
                cusMsg->show(this, CMsg::CWarning, "维护校正", "维护信息为空");
                this->isEmptyData("通信异常：维护信息为空");
            }
            else{
                cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
                ui->jiaozheng->setValue(instruct->weiHuData[1].toInt());
            }
        }
        else{
            cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
            ui->jiaozheng->setValue(instruct->weiHuData[1].toInt());
        }
    });


    connect(ui->lockJiaozhengBtn2, &QPushButton::clicked, this, [=](){
        instruct->weiHuData.clear();

        QString zhankongbi = ui->jiaozheng->text();
        /*发送数据前校验是否连接*/
        if(!instruct->m_socketClient->isConnected()){
            instruct->establishConnection(ip, port.toInt());
        }
        instruct->sendWeihuMensuojiaozheng(zhankongbi, QString::number(2));
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        if(instruct->weiHuData.size() == 0){
            /*发送数据前校验是否连接*/
            if(!instruct->m_socketClient->isConnected()){
                instruct->establishConnection(ip, port.toInt());
            }
            instruct->sendWeihuMensuojiaozheng(zhankongbi, QString::number(2));
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            if(instruct->weiHuData.size() == 0){
                cusMsg->show(this, CMsg::CWarning, "维护校正", "维护信息为空");
                this->isEmptyData("通信异常：维护信息为空");
            }
            else{
                cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
                //                ui->jiaozheng->setValue(instruct->weiHuData[1].toInt());
            }
        }
        else{
            cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
            //            ui->jiaozheng->setValue(instruct->weiHuData[1].toInt());
        }
    });


    connect(ui->kaiguanBtn, &QPushButton::clicked, this, [=](){
        instruct->weiHuData.clear();
        QString tongdao = QString::number(ui->kaiguanHole->currentIndex() + 1);
        QString kaiguan;
        if(ui->kaiguanOn->isChecked() == true){kaiguan = "0";}
        else if(ui->kaiguanOff->isChecked() == true){kaiguan = "1";}
        /*发送数据前校验是否连接*/
        if(!instruct->m_socketClient->isConnected()){
            instruct->establishConnection(ip, port.toInt());
        }
        instruct->sendWeihuTongdaoKaiguan(tongdao, kaiguan, QString::number(3));
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        if(instruct->weiHuData.size() == 0){
            /*发送数据前校验是否连接*/
            if(!instruct->m_socketClient->isConnected()){
                instruct->establishConnection(ip, port.toInt());
            }
            /*发送数据前校验是否连接*/
            if(!instruct->m_socketClient->isConnected()){
                instruct->establishConnection(ip, port.toInt());
            }
            instruct->sendWeihuTongdaoKaiguan(tongdao, kaiguan, QString::number(3));
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            if(instruct->weiHuData.size() == 0){
                cusMsg->show(this, CMsg::CWarning, "维护校正", "维护信息为空");
                this->isEmptyData("通信异常：维护信息为空");
            }
            else{
                cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
                //                ui->kaiguanHole->setCurrentIndex(instruct->weiHuData[1].toInt() - 1);
                //                if(instruct->weiHuData[2] == "0"){
                //                    ui->kaiguanOn->setChecked(true);
                //                }
                //                else if(instruct->weiHuData[2] == "1"){
                //                    ui->kaiguanOff->setChecked(true);
                //                }
            }
        }
        else{
            cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
            //            ui->kaiguanHole->setCurrentIndex(instruct->weiHuData[1].toInt() - 1);
            //            if(instruct->weiHuData[2] == "0"){
            //                ui->kaiguanOn->setChecked(true);
            //            }
            //            else if(instruct->weiHuData[2] == "1"){
            //                ui->kaiguanOff->setChecked(true);
            //            }
        }
    });

    connect(ui->kaiguanBtn_1, &QPushButton::clicked, this, [=](){
        instruct->weiHuData.clear();
        QString tongdao = QString::number(ui->kaiguanHole->currentIndex() + 1);
        QString kaiguan;
        if(ui->kaiguanOn->isChecked() == true){kaiguan = "0";}
        else if(ui->kaiguanOff->isChecked() == true){kaiguan = "1";}
        /*发送数据前校验是否连接*/
        if(!instruct->m_socketClient->isConnected()){
            instruct->establishConnection(ip, port.toInt());
        }
        instruct->sendWeihuTongdaoKaiguan(tongdao, kaiguan, QString::number(1));
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        if(instruct->weiHuData.size() == 0){
            /*发送数据前校验是否连接*/
            if(!instruct->m_socketClient->isConnected()){
                instruct->establishConnection(ip, port.toInt());
            }
            /*发送数据前校验是否连接*/
            if(!instruct->m_socketClient->isConnected()){
                instruct->establishConnection(ip, port.toInt());
            }
            instruct->sendWeihuTongdaoKaiguan(tongdao, kaiguan, QString::number(1));
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            if(instruct->weiHuData.size() == 0){
                cusMsg->show(this, CMsg::CWarning, "维护校正", "维护信息为空");
                this->isEmptyData("通信异常：维护信息为空");
            }
            else{
                cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
                ui->kaiguanHole->setCurrentIndex(instruct->weiHuData[1].toInt() - 1);
                if(instruct->weiHuData[2] == "0"){
                    ui->kaiguanOn->setChecked(true);
                }
                else if(instruct->weiHuData[2] == "1"){
                    ui->kaiguanOff->setChecked(true);
                }
            }
        }
        else{
            cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
            ui->kaiguanHole->setCurrentIndex(instruct->weiHuData[1].toInt() - 1);
            if(instruct->weiHuData[2] == "0"){
                ui->kaiguanOn->setChecked(true);
            }
            else if(instruct->weiHuData[2] == "1"){
                ui->kaiguanOff->setChecked(true);
            }
        }
    });


    connect(ui->tongdaozhiBtn1, &QPushButton::clicked, this, [=](){
        instruct->weiHuData.clear();

        QString tongdao = QString::number(ui->tongdaozhiHole->currentIndex() + 1);
        QString yingguangzhi = "";
        QString AD = "";
        /*发送数据前校验是否连接*/
        if(!instruct->m_socketClient->isConnected()){
            instruct->establishConnection(ip, port.toInt());
        }
        instruct->sendWeihuTongdaozhi(tongdao, yingguangzhi, AD, QString::number(1));
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        if(instruct->weiHuData.size() == 0){
            /*发送数据前校验是否连接*/
            if(!instruct->m_socketClient->isConnected()){
                instruct->establishConnection(ip, port.toInt());
            }
            instruct->sendWeihuTongdaozhi(tongdao, yingguangzhi, AD, QString::number(1));
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            if(instruct->weiHuData.size() == 0){
                cusMsg->show(this, CMsg::CWarning, "维护校正", "维护信息为空");
                this->isEmptyData("通信异常：维护信息为空");
            }
            else{
                cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
                ui->tongdaozhiHole->setCurrentIndex(instruct->weiHuData[1].toInt() - 1);
                ui->tongdaozhiYingguang->setText(instruct->weiHuData[2]);
                ui->tongdaozhiAD->setText(instruct->weiHuData[3]);
            }
        }
        else{
            cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
            ui->tongdaozhiHole->setCurrentIndex(instruct->weiHuData[1].toInt() - 1);
            ui->tongdaozhiYingguang->setText(instruct->weiHuData[2]);
            ui->tongdaozhiAD->setText(instruct->weiHuData[3]);
        }
    });

    connect(ui->tongdaozhiBtn2, &QPushButton::clicked, this, [=](){
        instruct->weiHuData.clear();
        QString tongdao = QString::number(ui->tongdaozhiHole->currentIndex() + 1);
        QString yingguangzhi = "";
        QString AD = "";
        /*发送数据前校验是否连接*/
        if(!instruct->m_socketClient->isConnected()){
            instruct->establishConnection(ip, port.toInt());
        }
        instruct->sendWeihuTongdaozhi(tongdao, yingguangzhi, AD, QString::number(2));
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        if(instruct->weiHuData.size() == 0){
            /*发送数据前校验是否连接*/
            if(!instruct->m_socketClient->isConnected()){
                instruct->establishConnection(ip, port.toInt());
            }
            instruct->sendWeihuTongdaozhi(tongdao, yingguangzhi, AD, QString::number(2));
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            if(instruct->weiHuData.size() == 0){
                cusMsg->show(this, CMsg::CWarning, "维护校正", "维护信息为空");
                this->isEmptyData("通信异常：维护信息为空");
            }
            else{
                cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
                ui->tongdaozhiHole->setCurrentIndex(instruct->weiHuData[1].toInt() - 1);
                ui->tongdaozhiYingguang->setText(instruct->weiHuData[2]);
                ui->tongdaozhiAD->setText(instruct->weiHuData[3]);
            }
        }
        else{
            cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
            ui->tongdaozhiHole->setCurrentIndex(instruct->weiHuData[1].toInt() - 1);
            ui->tongdaozhiYingguang->setText(instruct->weiHuData[2]);
            ui->tongdaozhiAD->setText(instruct->weiHuData[3]);
        }
    });

    connect(ui->qiangduBtn1, &QPushButton::clicked, this, [=](){
        instruct->weiHuData.clear();
        QString tongdao = QString::number(ui->qiangduHole->currentIndex() + 1);
        QString qiangduzhi = ui->qiangduZhi->text();
        /*发送数据前校验是否连接*/
        if(!instruct->m_socketClient->isConnected()){
            instruct->establishConnection(ip, port.toInt());
        }
        instruct->sendWeihuJifaqiangdu(tongdao, qiangduzhi, QString::number(1));
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        if(instruct->weiHuData.size() == 0){
            /*发送数据前校验是否连接*/
            if(!instruct->m_socketClient->isConnected()){
                instruct->establishConnection(ip, port.toInt());
            }
            instruct->sendWeihuJifaqiangdu(tongdao, qiangduzhi, QString::number(1));
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            if(instruct->weiHuData.size() == 0){
                cusMsg->show(this, CMsg::CWarning, "维护校正", "维护信息为空");
                this->isEmptyData("通信异常：维护信息为空");
            }
            else{
                cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
                ui->qiangduHole->setCurrentIndex(instruct->weiHuData[1].toInt() - 1);
                ui->qiangduZhi->setValue(instruct->weiHuData[2].toInt());
            }
        }
        else{
            cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
            ui->qiangduHole->setCurrentIndex(instruct->weiHuData[1].toInt() - 1);
            ui->qiangduZhi->setValue(instruct->weiHuData[2].toInt());
        }
    });

    connect(ui->qiangduBtn2, &QPushButton::clicked, this, [=](){
        instruct->weiHuData.clear();
        QString tongdao = QString::number(ui->qiangduHole->currentIndex() + 1);
        QString qiangduzhi = ui->qiangduZhi->text();
        /*发送数据前校验是否连接*/
        if(!instruct->m_socketClient->isConnected()){
            instruct->establishConnection(ip, port.toInt());
        }
        instruct->sendWeihuJifaqiangdu(tongdao, qiangduzhi, QString::number(2));
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        if(instruct->weiHuData.size() == 0){
            /*发送数据前校验是否连接*/
            if(!instruct->m_socketClient->isConnected()){
                instruct->establishConnection(ip, port.toInt());
            }
            instruct->sendWeihuJifaqiangdu(tongdao, qiangduzhi, QString::number(2));
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            if(instruct->weiHuData.size() == 0){
                cusMsg->show(this, CMsg::CWarning, "维护校正", "维护信息为空");
                this->isEmptyData("通信异常：维护信息为空");
            }
            else{
                cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
                //                ui->qiangduHole->setCurrentIndex(instruct->weiHuData[1].toInt() - 1);
                //                ui->qiangduZhi->setValue(instruct->weiHuData[2].toInt());
            }
        }
        else{
            cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
            //            ui->qiangduHole->setCurrentIndex(instruct->weiHuData[1].toInt() - 1);
            //            ui->qiangduZhi->setValue(instruct->weiHuData[2].toInt());
        }
    });



    connect(ui->zengyiBtn1, &QPushButton::clicked, this, [=](){
        instruct->weiHuData.clear();
        QString tongdao = QString::number(ui->zengyiHole->currentIndex() + 1);
        QString zengyizhi = ui->zengyiZhi->text();
        /*发送数据前校验是否连接*/
        if(!instruct->m_socketClient->isConnected()){
            instruct->establishConnection(ip, port.toInt());
        }
        instruct->sendWeihuYingguangzengyi(tongdao, zengyizhi, QString::number(1));
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        if(instruct->weiHuData.size() == 0){
            /*发送数据前校验是否连接*/
            if(!instruct->m_socketClient->isConnected()){
                instruct->establishConnection(ip, port.toInt());
            }
            instruct->sendWeihuYingguangzengyi(tongdao, zengyizhi, QString::number(1));
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            if(instruct->weiHuData.size() == 0){
                cusMsg->show(this, CMsg::CWarning, "维护校正", "维护信息为空");
                this->isEmptyData("通信异常：维护信息为空");
            }
            else{
                cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
                ui->zengyiHole->setCurrentIndex(instruct->weiHuData[1].toInt() - 1);
                ui->zengyiZhi->setValue(instruct->weiHuData[2].toInt());
            }
        }
        else{
            cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
            ui->zengyiHole->setCurrentIndex(instruct->weiHuData[1].toInt() - 1);
            ui->zengyiZhi->setValue(instruct->weiHuData[2].toInt());
        }
    });

    connect(ui->zengyiBtn2, &QPushButton::clicked, this, [=](){
        instruct->weiHuData.clear();
        QString tongdao = QString::number(ui->zengyiHole->currentIndex() + 1);
        QString zengyizhi = ui->zengyiZhi->text();
        /*发送数据前校验是否连接*/
        if(!instruct->m_socketClient->isConnected()){
            instruct->establishConnection(ip, port.toInt());
        }
        instruct->sendWeihuYingguangzengyi(tongdao, zengyizhi, QString::number(2));
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        if(instruct->weiHuData.size() == 0){
            /*发送数据前校验是否连接*/
            if(!instruct->m_socketClient->isConnected()){
                instruct->establishConnection(ip, port.toInt());
            }
            instruct->sendWeihuYingguangzengyi(tongdao, zengyizhi, QString::number(2));
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            if(instruct->weiHuData.size() == 0){
                cusMsg->show(this, CMsg::CWarning, "维护校正", "维护信息为空");
                this->isEmptyData("通信异常：维护信息为空");
            }
            else{
                cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
                //                ui->zengyiHole->setCurrentIndex(instruct->weiHuData[1].toInt() - 1);
                //                ui->zengyiZhi->setValue(instruct->weiHuData[2].toInt());
            }
        }
        else{
            cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
            //            ui->zengyiHole->setCurrentIndex(instruct->weiHuData[1].toInt() - 1);
            //            ui->zengyiZhi->setValue(instruct->weiHuData[2].toInt());
        }
    });


    connect(ui->zhankongbi_1, &QPushButton::clicked, this, [=](){
        instruct->weiHuData.clear();
        QString zhankongbi = ui->jiaresi->text();
        /*发送数据前校验是否连接*/
        if(!instruct->m_socketClient->isConnected()){
            instruct->establishConnection(ip, port.toInt());
        }
        instruct->sendWeihuJiaresi(zhankongbi, QString::number(1));
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        if(instruct->weiHuData.size() == 0){
            /*发送数据前校验是否连接*/
            if(!instruct->m_socketClient->isConnected()){
                instruct->establishConnection(ip, port.toInt());
            }
            instruct->sendWeihuJiaresi(zhankongbi, QString::number(1));
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            if(instruct->weiHuData.size() == 0){
                cusMsg->show(this, CMsg::CWarning, "维护校正", "维护信息为空");
                this->isEmptyData("通信异常：维护信息为空");
            }
            else{
                cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
                qDebug() << "加热丝信息" << instruct->weiHuData[1];
                ui->jiaresi->setValue(instruct->weiHuData[1].toInt());
            }
        }
        else{
            cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
            ui->jiaresi->setValue(instruct->weiHuData[1].toInt());
        }

    });
    connect(ui->zhankongbi_2, &QPushButton::clicked, this, [=](){
        instruct->weiHuData.clear();
        QString zhankongbi = ui->jiaresi->text();
        /*发送数据前校验是否连接*/
        if(!instruct->m_socketClient->isConnected()){
            instruct->establishConnection(ip, port.toInt());
        }
        instruct->sendWeihuJiaresi(zhankongbi, QString::number(2));
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        if(instruct->weiHuData.size() == 0){
            /*发送数据前校验是否连接*/
            if(!instruct->m_socketClient->isConnected()){
                instruct->establishConnection(ip, port.toInt());
            }
            instruct->sendWeihuJiaresi(zhankongbi, QString::number(2));
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            if(instruct->weiHuData.size() == 0){
                cusMsg->show(this, CMsg::CWarning, "维护校正", "维护信息为空");
                this->isEmptyData("通信异常：维护信息为空");
            }
            else{
                cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
            }
        }
        else{
            cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
        }
    });

    /* 校验传感器温度维护 */
    connect(ui->wenduBtn, &QPushButton::clicked, this, [=](){
        instruct->weiHuData.clear();
        QString wendu1 = "";
        QString wendu2 = "";
        /*发送数据前校验是否连接*/
        if(!instruct->m_socketClient->isConnected()){
            instruct->establishConnection(ip, port.toInt());
        }
        instruct->sendWeihuSensorwendu(wendu1, wendu2, QString::number(1));
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        if(instruct->weiHuData.size() == 0){
            /*发送数据前校验是否连接*/
            if(!instruct->m_socketClient->isConnected()){
                instruct->establishConnection(ip, port.toInt());
            }
            instruct->sendWeihuSensorwendu(wendu1, wendu2, QString::number(1));
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            if(instruct->weiHuData.size() == 0){
                cusMsg->show(this, CMsg::CWarning, "维护校正", "维护信息为空");
                this->isEmptyData("通信异常：维护信息为空");
            }
            else{
                cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
                ui->wendu1->setText(QString::number(instruct->weiHuData[1].toFloat()/10.0));
                ui->wendu2->setText(QString::number(instruct->weiHuData[2].toFloat()/10.0));
            }
        }
        else{
            cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
            ui->wendu1->setText(QString::number(instruct->weiHuData[1].toFloat()/10.0));
            ui->wendu2->setText(QString::number(instruct->weiHuData[2].toFloat()/10.0));
        }
    });

    /* 校验扰流风扇维护 */
    connect(ui->raoliufengshanBtn1, &QPushButton::clicked, this, [=](){
        instruct->weiHuData.clear();
        QString zhankongbi = ui->raoliuZhankongbi->text();

        /*发送数据前校验是否连接*/
        if(!instruct->m_socketClient->isConnected()){
            instruct->establishConnection(ip, port.toInt());
        }
        instruct->sendWeihuRaoluanfeng(zhankongbi, QString::number(1));
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        if(instruct->weiHuData.size() == 0){
            /*发送数据前校验是否连接*/
            if(!instruct->m_socketClient->isConnected()){
                instruct->establishConnection(ip, port.toInt());
            }
            instruct->sendWeihuRaoluanfeng(zhankongbi, QString::number(1));
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            if(instruct->weiHuData.size() == 0){
                cusMsg->show(this, CMsg::CWarning, "维护校正", "维护信息为空");
                this->isEmptyData("通信异常：维护信息为空");
            }
            else{
                cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
                ui->raoliuZhankongbi->setValue(instruct->weiHuData[1].toInt());
            }
        }
        else{
            cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
            ui->raoliuZhankongbi->setValue(instruct->weiHuData[1].toInt());
        }
    });

    connect(ui->raoliufengshanBtn2, &QPushButton::clicked, this, [=](){
        instruct->weiHuData.clear();
        QString zhankongbi = ui->raoliuZhankongbi->text();
        /*发送数据前校验是否连接*/
        if(!instruct->m_socketClient->isConnected()){
            instruct->establishConnection(ip, port.toInt());
        }
        instruct->sendWeihuRaoluanfeng(zhankongbi, QString::number(2));
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        if(instruct->weiHuData.size() == 0){
            /*发送数据前校验是否连接*/
            if(!instruct->m_socketClient->isConnected()){
                instruct->establishConnection(ip, port.toInt());
            }
            instruct->sendWeihuRaoluanfeng(zhankongbi, QString::number(2));
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            if(instruct->weiHuData.size() == 0){
                cusMsg->show(this, CMsg::CWarning, "维护校正", "维护信息为空");
                this->isEmptyData("通信异常：维护信息为空");
            }
            else{
                cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
                //                ui->raoliuZhankongbi->setValue(instruct->weiHuData[1].toInt());
            }
        }
        else{
            cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
            //            ui->raoliuZhankongbi->setValue(instruct->weiHuData[1].toInt());
        }
    });

    connect(ui->fengshankaiguanBtn, &QPushButton::clicked, this, [=](){
        instruct->weiHuData.clear();
        QString kaiguan;
        if(ui->fengshanOn->isChecked() == true){kaiguan = "0";}
        else if(ui->fengshanOff->isChecked() == true){kaiguan = "1";}
        /*发送数据前校验是否连接*/
        if(!instruct->m_socketClient->isConnected()){
            instruct->establishConnection(ip, port.toInt());
        }
        instruct->sendWeihuRaoluanfengshanKaiguan(kaiguan, QString::number(3));
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        if(instruct->weiHuData.size() == 0){
            /*发送数据前校验是否连接*/
            if(!instruct->m_socketClient->isConnected()){
                instruct->establishConnection(ip, port.toInt());
            }
            instruct->sendWeihuRaoluanfengshanKaiguan(kaiguan, QString::number(3));
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            if(instruct->weiHuData.size() == 0){
                cusMsg->show(this, CMsg::CWarning, "维护校正", "维护信息为空");
                this->isEmptyData("通信异常：维护信息为空");
            }
            else{
                cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
                //                if(instruct->weiHuData[1] == "0"){
                //                    ui->fengshanOn->setChecked(true);
                //                }
                //                else if(instruct->weiHuData[1] == "1"){
                //                    ui->fengshanOff->setChecked(true);
                //                }
            }
        }
        else{
            cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
            //            if(instruct->weiHuData[1] == "0"){
            //                ui->fengshanOn->setChecked(true);
            //            }
            //            else if(instruct->weiHuData[1] == "1"){
            //                ui->fengshanOff->setChecked(true);
            //            }
        }
    });

    connect(ui->paifengfengshanBtn, &QPushButton::clicked, this, [=](){
        instruct->weiHuData.clear();
        QString kaiguan;
        if(ui->paifengOn->isChecked() == true){kaiguan = "0";}
        else if(ui->paifengOff->isChecked() == true){kaiguan = "1";}
        /*发送数据前校验是否连接*/
        if(!instruct->m_socketClient->isConnected()){
            instruct->establishConnection(ip, port.toInt());
        }
        instruct->sendWeihuPaifengfengshan(kaiguan, QString::number(3));
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        if(instruct->weiHuData.size() == 0){
            /*发送数据前校验是否连接*/
            if(!instruct->m_socketClient->isConnected()){
                instruct->establishConnection(ip, port.toInt());
            }
            instruct->sendWeihuPaifengfengshan(kaiguan, QString::number(3));
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            if(instruct->weiHuData.size() == 0){
                cusMsg->show(this, CMsg::CWarning, "维护校正", "维护信息为空");
                this->isEmptyData("通信异常：维护信息为空");
            }
            else{
                cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
                //                if(instruct->weiHuData[1] == "0"){
                //                    ui->paifengOn->setChecked(true);
                //                }
                //                else if(instruct->weiHuData[1] == "1"){
                //                    ui->paifengOff->setChecked(true);
                //                }
            }
        }
        else{
            cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
            //            if(instruct->weiHuData[1] == "0"){
            //                ui->paifengOn->setChecked(true);
            //            }
            //            else if(instruct->weiHuData[1] == "1"){
            //                ui->paifengOff->setChecked(true);
            //            }
        }
    });

    connect(ui->duiliufengshanBtn1, &QPushButton::clicked, this, [=](){
        instruct->weiHuData.clear();
        QString zhankongbi = ui->duiliu->text();
        /*发送数据前校验是否连接*/
        if(!instruct->m_socketClient->isConnected()){
            instruct->establishConnection(ip, port.toInt());
        }
        instruct->sendWeihuDuiliufengshan(zhankongbi, QString::number(1));
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        if(instruct->weiHuData.size() == 0){
            /*发送数据前校验是否连接*/
            if(!instruct->m_socketClient->isConnected()){
                instruct->establishConnection(ip, port.toInt());
            }
            instruct->sendWeihuDuiliufengshan(zhankongbi, QString::number(1));
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            if(instruct->weiHuData.size() == 0){
                cusMsg->show(this, CMsg::CWarning, "维护校正", "维护信息为空");
                this->isEmptyData("通信异常：维护信息为空");
            }
            else{
                cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
                ui->duiliu->setValue(instruct->weiHuData[1].toInt());
            }
        }
        else{
            cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
            ui->duiliu->setValue(instruct->weiHuData[1].toInt());
        }
    });

    connect(ui->duiliufengshanBtn2, &QPushButton::clicked, this, [=](){
        instruct->weiHuData.clear();
        QString zhankongbi = ui->duiliu->text();
        /*发送数据前校验是否连接*/
        if(!instruct->m_socketClient->isConnected()){
            instruct->establishConnection(ip, port.toInt());
        }
        instruct->sendWeihuDuiliufengshan(zhankongbi, QString::number(2));
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        if(instruct->weiHuData.size() == 0){
            /*发送数据前校验是否连接*/
            if(!instruct->m_socketClient->isConnected()){
                instruct->establishConnection(ip, port.toInt());
            }
            instruct->sendWeihuDuiliufengshan(zhankongbi, QString::number(2));
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            if(instruct->weiHuData.size() == 0){
                cusMsg->show(this, CMsg::CWarning, "维护校正", "维护信息为空");
                this->isEmptyData("通信异常：维护信息为空");
            }
            else{
                cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
                //                ui->duiliu->setValue(instruct->weiHuData[1].toInt());
            }
        }
        else{
            cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
            //            ui->duiliu->setValue(instruct->weiHuData[1].toInt());
        }
    });

    connect(ui->jiaozhunBtn1, &QPushButton::clicked, this, [=](){
        instruct->weiHuData.clear();
        QString wendu = ui->chuanganqi->text();

        /*发送数据前校验是否连接*/
        if(!instruct->m_socketClient->isConnected()){
            instruct->establishConnection(ip, port.toInt());
        }
        instruct->sendWeihuBiaozhunWendu("0", QString::number(1));
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
        /* 渲染指令到UI */
        this->renderWeihuZhiling();

        if(instruct->weiHuData.size() == 0){
            /*发送数据前校验是否连接*/
            if(!instruct->m_socketClient->isConnected()){
                instruct->establishConnection(ip, port.toInt());
            }
            instruct->sendWeihuBiaozhunWendu("0", QString::number(1));
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            if(instruct->weiHuData.size() == 0){
                cusMsg->show(this, CMsg::CWarning, "维护校正", "维护信息为空");
                this->isEmptyData("通信异常：维护信息为空");
            }
            else{
                cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
                ui->chuanganqi->setValue(instruct->weiHuData[1].toDouble()/10);
            }
        }
        else{
            cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
            ui->chuanganqi->setValue(instruct->weiHuData[1].toDouble()/10);
        }
    });

    connect(ui->jiaozhunBtn2, &QPushButton::clicked, this, [=](){
        instruct->weiHuData.clear();
        QString wendu = ui->chuanganqi->text();
        /*发送数据前校验是否连接*/
        if(!instruct->m_socketClient->isConnected()){
            instruct->establishConnection(ip, port.toInt());
        }
        instruct->sendWeihuBiaozhunWendu(wendu, QString::number(2));
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        sleep(3000);
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        if(instruct->weiHuData.size() == 0){
            /*发送数据前校验是否连接*/
            if(!instruct->m_socketClient->isConnected()){
                instruct->establishConnection(ip, port.toInt());
            }

            instruct->sendWeihuBiaozhunWendu(wendu, QString::number(2));
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            sleep(3000);
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            if(instruct->weiHuData.size() == 0){
                cusMsg->show(this, CMsg::CWarning, "维护校正", "维护信息为空");
                this->isEmptyData("通信异常：维护信息为空");
            }
            else{
                cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
                //                ui->chuanganqi->setValue(instruct->weiHuData[1].toDouble()/10);

            }
        }
        else{
            cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
            //            ui->chuanganqi->setValue(instruct->weiHuData[1].toDouble()/10);
        }
    });

    connect(ui->weizhijiaozhunBtn1, &QPushButton::clicked, this, [=](){
        instruct->weiHuData.clear();
        QString tongdao = QString::number(ui->weizhiHole->currentIndex() + 1);
        QString step = ui->weizhiStep->text();
        /*发送数据前校验是否连接*/
        if(!instruct->m_socketClient->isConnected()){
            instruct->establishConnection(ip, port.toInt());
        }
        instruct->sendWeihuReshiyuandian(tongdao, step, QString::number(1));
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        if(instruct->weiHuData.size() == 0){
            /*发送数据前校验是否连接*/
            if(!instruct->m_socketClient->isConnected()){
                instruct->establishConnection(ip, port.toInt());
            }
            instruct->sendWeihuReshiyuandian(tongdao, step, QString::number(1));
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            if(instruct->weiHuData.size() == 0){
                cusMsg->show(this, CMsg::CWarning, "维护校正", "维护信息为空");
                this->isEmptyData("通信异常：维护信息为空");
            }
            else{
                cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
                ui->weizhiHole->setCurrentIndex(instruct->weiHuData[1].toInt() - 1);
                ui->weizhiStep->setValue(instruct->weiHuData[2].toDouble());
            }
        }
        else{
            cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
            ui->weizhiHole->setCurrentIndex(instruct->weiHuData[1].toInt() - 1);
            ui->weizhiStep->setValue(instruct->weiHuData[2].toDouble());
        }
    });

    connect(ui->weizhijiaozhunBtn2, &QPushButton::clicked, this, [=](){
        instruct->weiHuData.clear();
        QString tongdao = QString::number(ui->weizhiHole->currentIndex() + 1);
        QString step = ui->weizhiStep->text();
        /*发送数据前校验是否连接*/
        if(!instruct->m_socketClient->isConnected()){
            instruct->establishConnection(ip, port.toInt());
        }
        instruct->sendWeihuReshiyuandian(tongdao, step, QString::number(2));
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        sleep(8000);
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        if(instruct->weiHuData.size() == 0){
            /*发送数据前校验是否连接*/
            if(!instruct->m_socketClient->isConnected()){
                instruct->establishConnection(ip, port.toInt());
            }
            instruct->sendWeihuReshiyuandian(tongdao, step, QString::number(2));
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            sleep(8000);
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            if(instruct->weiHuData.size() == 0){
                cusMsg->show(this, CMsg::CWarning, "维护校正", "维护信息为空");
                this->isEmptyData("通信异常：维护信息为空");
            }
            else{
                cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
//                ui->weizhiHole->setCurrentIndex(instruct->weiHuData[1].toInt() - 1);
//                ui->weizhiStep->setValue(instruct->weiHuData[2].toDouble());
            }
        }
        else{
            cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
//            ui->weizhiHole->setCurrentIndex(instruct->weiHuData[1].toInt() - 1);
//            ui->weizhiStep->setValue(instruct->weiHuData[2].toDouble());
        }
    });

    connect(ui->weizhijiaozhunBtn3, &QPushButton::clicked, this, [=](){
        instruct->weiHuData.clear();
        QString tongdao = QString::number(ui->weizhiHole->currentIndex() + 1);
        QString step = ui->weizhiStep->text();
        /*发送数据前校验是否连接*/
        if(!instruct->m_socketClient->isConnected()){
            instruct->establishConnection(ip, port.toInt());
        }
        instruct->sendWeihuReshiyuandian(tongdao, step, QString::number(3));
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        sleep(3000);
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        if(instruct->weiHuData.size() == 0){
            /*发送数据前校验是否连接*/
            if(!instruct->m_socketClient->isConnected()){
                instruct->establishConnection(ip, port.toInt());
            }
            instruct->sendWeihuReshiyuandian(tongdao, step, QString::number(3));
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            sleep(3000);
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            if(instruct->weiHuData.size() == 0){
                cusMsg->show(this, CMsg::CWarning, "维护校正", "维护信息为空");
                this->isEmptyData("通信异常：维护信息为空");
            }
            else{
                cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
                //                ui->weizhiHole->setCurrentIndex(instruct->weiHuData[1].toInt() - 1);
                //                ui->weizhiStep->setValue(instruct->weiHuData[2].toDouble());
            }
        }
        else{
            cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
            //            ui->weizhiHole->setCurrentIndex(instruct->weiHuData[1].toInt() - 1);
            //            ui->weizhiStep->setValue(instruct->weiHuData[2].toDouble());
        }
    });

    connect(ui->zhuansujiaozhunBtn1, &QPushButton::clicked, this, [=](){
        instruct->weiHuData.clear();
        QString haocai, kongwei, yuandian, pingjun;

        haocai = ui->haocai->currentText();
        kongwei = QString::number(ui->kongwei->value());
        yuandian = QString::number(ui->yuandianpiancha->value());
        pingjun = QString::number(ui->pingjunpiancha->value());

        if(haocai.contains("管式")) haocai = "3";
        else if(haocai.contains("芯片")) haocai = "2";

        /*发送数据前校验是否连接*/
        if(!instruct->m_socketClient->isConnected()){
            instruct->establishConnection(ip, port.toInt());
        }

        instruct->sendWeihuKongweipiancha(haocai, kongwei, yuandian, pingjun, "1");

        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        if(instruct->weiHuData.size() == 0){
            /*发送数据前校验是否连接*/
            if(!instruct->m_socketClient->isConnected()){
                instruct->establishConnection(ip, port.toInt());
            }
            instruct->sendWeihuKongweipiancha(haocai, kongwei, yuandian, pingjun, "1");
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            if(instruct->weiHuData.size() == 0){
                cusMsg->show(this, CMsg::CWarning, "维护校正", "维护信息为空");
                this->isEmptyData("通信异常：维护信息为空");
            }
            else{
                cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
                /* 耗材类型 */
                if(instruct->weiHuData[1] == "2"){
                    ui->haocai->setCurrentIndex(0);
                }else if(instruct->weiHuData[1] == "3"){
                    ui->haocai->setCurrentIndex(1);
                }
                /* 孔位 */
                ui->kongwei->setValue((instruct->weiHuData[2]).toInt());
                /* 原点偏差 */
                ui->yuandianpiancha->setValue((instruct->weiHuData[3]).toInt());
                /* 平均偏差 */
                ui->pingjunpiancha->setValue((instruct->weiHuData[4]).toInt());
            }
        }
        else{
            cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
            /* 耗材类型 */
            if(instruct->weiHuData[1] == "2"){
                ui->haocai->setCurrentIndex(0);
            }else if(instruct->weiHuData[1] == "3"){
                ui->haocai->setCurrentIndex(1);
            }
            /* 孔位 */
            ui->kongwei->setValue((instruct->weiHuData[2]).toInt());
            /* 原点偏差 */
            ui->yuandianpiancha->setValue((instruct->weiHuData[3]).toInt());
            /* 平均偏差 */
            ui->pingjunpiancha->setValue((instruct->weiHuData[4]).toInt());
        }
    });

    connect(ui->zhuansujiaozhunBtn2, &QPushButton::clicked, this, [=](){
        instruct->weiHuData.clear();
        QString haocai, kongwei, yuandian, pingjun;

        haocai = ui->haocai->currentText();
        kongwei = QString::number(ui->kongwei->value());
        yuandian = QString::number(ui->yuandianpiancha->value());
        pingjun = QString::number(ui->pingjunpiancha->value());

        if(haocai.contains("管式")) haocai = "3";
        else if(haocai.contains("芯片")) haocai = "2";

        /*发送数据前校验是否连接*/
        if(!instruct->m_socketClient->isConnected()){
            instruct->establishConnection(ip, port.toInt());
        }

        instruct->sendWeihuKongweipiancha(haocai, kongwei, yuandian, pingjun, "2");

        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        if(instruct->weiHuData.size() == 0){
            /*发送数据前校验是否连接*/
            if(!instruct->m_socketClient->isConnected()){
                instruct->establishConnection(ip, port.toInt());
            }
            instruct->sendWeihuKongweipiancha(haocai, kongwei, yuandian, pingjun, "2");
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            if(instruct->weiHuData.size() == 0){
                cusMsg->show(this, CMsg::CWarning, "维护校正", "维护信息为空");
                this->isEmptyData("通信异常：维护信息为空");
            }
            else{
                cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
//                /* 耗材类型 */
//                if(instruct->weiHuData[1] == "2"){
//                    ui->haocai->setCurrentIndex(0);
//                }else if(instruct->weiHuData[1] == "3"){
//                    ui->haocai->setCurrentIndex(1);
//                }
//                /* 孔位 */
//                ui->kongwei->setValue((instruct->weiHuData[2]).toInt());
//                /* 原点偏差 */
//                ui->yuandianpiancha->setValue((instruct->weiHuData[3]).toInt());
//                /* 平均偏差 */
//                ui->pingjunpiancha->setValue((instruct->weiHuData[4]).toInt());
            }
        }
        else{
            cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
//            /* 耗材类型 */
//            if(instruct->weiHuData[1] == "2"){
//                ui->haocai->setCurrentIndex(0);
//            }else if(instruct->weiHuData[1] == "3"){
//                ui->haocai->setCurrentIndex(1);
//            }
//            /* 孔位 */
//            ui->kongwei->setValue((instruct->weiHuData[2]).toInt());
//            /* 原点偏差 */
//            ui->yuandianpiancha->setValue((instruct->weiHuData[3]).toInt());
//            /* 平均偏差 */
//            ui->pingjunpiancha->setValue((instruct->weiHuData[4]).toInt());
        }
    });

    connect(ui->zhuansujiaozhunBtn3, &QPushButton::clicked, this, [=](){
        instruct->weiHuData.clear();
        QString haocai, kongwei, yuandian, pingjun;

        haocai = ui->haocai->currentText();
        kongwei = QString::number(ui->kongwei->value());
        yuandian = QString::number(ui->yuandianpiancha->value());
        pingjun = QString::number(ui->pingjunpiancha->value());

        if(haocai.contains("管式")) haocai = "3";
        else if(haocai.contains("芯片")) haocai = "2";

        /*发送数据前校验是否连接*/
        if(!instruct->m_socketClient->isConnected()){
            instruct->establishConnection(ip, port.toInt());
        }

        instruct->sendWeihuKongweipiancha(haocai, kongwei, yuandian, pingjun, "3");

        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
        /* 渲染指令到UI */
        this->renderWeihuZhiling();
        if(instruct->weiHuData.size() == 0){
            /*发送数据前校验是否连接*/
            if(!instruct->m_socketClient->isConnected()){
                instruct->establishConnection(ip, port.toInt());
            }
            instruct->sendWeihuKongweipiancha(haocai, kongwei, yuandian, pingjun, "3");
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            sleep(EXPERIMENT_RUNNING_SLEEP_TIME);
            /* 渲染指令到UI */
            this->renderWeihuZhiling();
            if(instruct->weiHuData.size() == 0){
                cusMsg->show(this, CMsg::CWarning, "维护校正", "维护信息为空");
                this->isEmptyData("通信异常：维护信息为空");
            }
            else{
                cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
            }
        }
        else{
            cusMsg->show(this, CMsg::CWarning, "维护校正", instruct->weiHuData[0]);
        }
    });

    //    connect(ui->back, &QPushButton::clicked, this, [=](){
    //        this->close();
    //    });

    /* 设备改变 */
    connect(ui->devices_2, SIGNAL(currentIndexChanged(int)), this, SLOT(currentActiveChanged(int)));
}

maintain::~maintain()
{
    delete ui;
}

/* 活跃设备改变 */
void maintain::currentActiveChanged(int index){
    /* 获取当前选中设备 */
    ConnectedDeviceStruct tCDev = ui->devices_2->currentData().value<ConnectedDeviceStruct>();
    this->instruct = tCDev.instructionsService;
    this->ip = tCDev.dev.ip;
    this->port = tCDev.dev.port;
}

//void maintain::timerUpdate(){
//    QDateTime dataTime = QDateTime::currentDateTime();
//    QString date = dataTime.toString("yyyy-MM-dd hh:mm:ss dddd");

//    ui->dateLabel_2->setText(date);
//    ui->dateLabel_4->setText(date);
//    ui->dateLabel_5->setText(date);
//}

void maintain::sleep(int msec){
    QTime dieTime = QTime::currentTime().addMSecs(msec);
    while( QTime::currentTime() < dieTime )
        QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
}

void maintain::showEvent(QShowEvent *event){
    /* 清空设备列表 */
    ui->devices_2->clear();

    if(connectDeviceInfo.size() == 0){
        cusMsg->show(this, CMsg::CWarning, "维护", "设备列表为空！！");
        /* 所有页面无效 */
        ui->tabWidget->setEnabled(false);
    }
    else {
        ui->tabWidget->setEnabled(true);
        /* 渲染设备列表 */
        /* 遍历设备列表，加入已连接设备 */
        for(int i = 0; i < connectDeviceInfo.size(); i++){
            ConnectedDeviceStruct cDevStruct = connectDeviceInfo[i];
            QVariant deviceVariant = QVariant::fromValue(cDevStruct);
            /* 添加到设备列表中 */
            QString showDeviceInfo = connectDeviceInfo[i].dev.name;
            ui->devices_2->addItem(showDeviceInfo, deviceVariant);
        }
    }
}

void maintain::renderNotParseWeihuZhiling(){
    if(instruct->m_socketClient->isNotParseWritten){
        QString notParseZhiling = instruct->m_socketClient->returnNotParseZhiling2Ui();
        /* 渲染指令 */
        ui->weiHuZhiling->append(notParseZhiling);
    }
}

void maintain::renderWeihuZhiling(){
    //    qDebug() << instruct->m_socketClient->isWeihuWritten;
    /* 渲染未解析指令 */
    this->renderNotParseWeihuZhiling();

    if(instruct->m_socketClient->isWeihuWritten){
        /* 获取指令信息 */
        QString weihuZhiling = instruct->m_socketClient->returnWeiHu2Ui();
        /* 渲染指令信息 */
        ui->weiHuZhiling->append(weihuZhiling);
    }
}

void maintain::isEmptyData(QString emptyString){
    /* 渲染空数据信息 */
    ui->weiHuZhiling->append(emptyString);
}

/* 关闭窗口 */
void maintain::closeEvent(QCloseEvent *event){
    /* 断开设备 */
    if(connectDeviceInfo.size() != 0){
        if(instruct->m_socketClient->isConnected()){
            instruct->m_socketClient->closeSocket();
        }
    }
}
